package cn.ycc1.boot3rabbitmq.service.mq;

import cn.ycc1.boot3rabbitmq.service.VO.UserVO;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author ycc
 * @date 2024/10/28
 */
@Component
public class RabbitMQListener {
//    @RabbitListener(queues = "myQueue")
//    public void receiveMessage(String message) {
//        System.out.println("Received Message: " + message);
//    }

//    @RabbitListener(queues = "myQueue")
//    public void receiveMessage(UserVO message) {
//        try {
//            // Process the message
//            System.out.println("Received message: " + message);
//        } catch (Exception e) {
//            e.printStackTrace();
//            // Log the exception details
//        }
//    }

    @RabbitListener(queues = "myQueue")
    public void receiveMessage(UserVO userVO, Channel channel, Message message) throws IOException {

        System.out.println("Received message: " + userVO);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
